package com.hhs.storage.controller;


import com.hhs.storage.bean.BaseUser;
import com.hhs.storage.bean.Comsumer;
import com.hhs.storage.bean.InputParam;
import com.hhs.storage.bean.ResponseInfo;
import com.hhs.storage.service.BaseLogsService;
import com.hhs.storage.service.BaseUserService;
import com.hhs.storage.service.ComsumerService;
import org.springframework.util.StringUtils;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hhs
 * @since 2022-12-07
 */
@RestController
@RequestMapping("comsumer")
public class ComsumerController {
    @Resource
    ComsumerService comsumerService;
    @Resource
    private BaseLogsService baseLogsService;
    @RequestMapping(value = "table")
    public Map<String, Object> getAll(InputParam inputParam) {
        baseLogsService.log("客户管理","查询",null);

        return comsumerService.getAll(inputParam);
    }
    @PostMapping(value = "edit")
    public Map<String, Object> saveOrUpdate(Comsumer comsumer,String deleIdStr, MultipartFile[] qualificationCertificateList){
        if (StringUtils.isEmpty(comsumer.getId())){
            baseLogsService.log("客户管理","新增",null);
        }else{
            baseLogsService.log("客户管理","编辑",null);
        }
        return comsumerService.addOrUpdate(comsumer,deleIdStr,qualificationCertificateList);
    }
    @PostMapping(value = "dele")
    public Map dele(String id) {
        baseLogsService.log("客户管理","删除",null);

        return comsumerService.dele(id);
    }

    @GetMapping(value = "getById")
    public Map getById(String id) {
        if(!StringUtils.isEmpty(id)) {
            Comsumer comsumer = comsumerService.getById(id);
            return ResponseInfo.success(comsumer);
        }
        return ResponseInfo.success(null);
    }
}

